<?php
defined('_XR_EXEC') or die();
/**
 * test module
 */
class user_model extends model
{ 
	public function __construct() {
		parent::__construct();
	}

	/* 用户行为日志记录 */
	public function userlog($user_id,$logs=''){
		$db = factory::getdbo();
		return $db->insert('logs',array(
			'user_id'=>intval($user_id),
			'dates'=>'now()',
			'clientip'=>ip::client(),
			'serverip'=>ip::server(),
			'logs'=>$logs
		));
	} 
	# 自定义登录验证，函数名称必须为loginCheck
	function loginCheck($type,$doing=true){
		switch($type){
			case "admin":		  //管理员
				if(!isset($_SESSION['sys_admin'])){
					if($doing) url::msgBox('未登录或登录超时，请重新登录!',url::build('login','admin'));
					else return false;
				}
 				return true;
			case "member":		  //会员
				if(!isset($_SESSION['sys_user'])){
					if($doing) url::msgBox('未登录或登录超时，请重新登录!',url::build('login','index'));
					else return false;
				}
 				return true;
			case "user0":		  //乐园卡
				if(!isset($_SESSION['sys_user'])){
					if($doing) url::msgBox('未登录或登录超时，请重新登录!',url::build('login','index'));
					else return false;
				}
 				return true;
				//判断是否计划配送会员
				$m_member = factory::module('member');
				$sendtype = $m_member->getusersendtype();
				if($sendtype != '0'){
					if($doing) url::jump(url::build('member','index'));
					else return false;
				}
 				return true;
			case "user1":		  //田园卡
				if(!isset($_SESSION['sys_user'])){
					if($doing) url::msgBox('未登录或登录超时，请重新登录!',url::build('login','index'));
					else return false;
				}
 				return true;
				//判断是否订单会员
				$m_member = factory::module('member');
				$sendtype = $m_member->getusersendtype();
				if($sendtype != '1'){
					if($doing) url::jump(url::build('member','index'));
					else return false;
				}
 				return true;
			default:
				return false;
		}
	}
	/* 用户登录，更新最后登录时间和IP */
	public function updatelogin($user_id){
		$db = factory::getdbo();
		$counts = $db->loadresult('select login_count from t_user where id="'.$user_id.'" ') + 1;
		return $db->update('user',array(
			'id'=>$user_id,
			'login_date'=>'now()',
			'login_count'=>$counts,
			'login_ip'=>func::get_client_ip()
		));
	}
	
}

?>